package apptoko.com.network;

import android.app.ProgressDialog;
import android.content.Context;
import android.os.AsyncTask;
import android.widget.Toast;
import apptoko.com.util.StorageUtils;
import apptoko.com.util.Utils;

import apptoko.com.R;
;

public class BackupApkTask extends AsyncTask<String, Void, String>{

	private Context context;
	private ProgressDialog pDialog;
	
	public BackupApkTask(Context context){
		this.context = context;
	}
	
	@Override
	protected void onPostExecute(String result) {
		if(result.equals("error")){
			Toast.makeText(context, R.string.backup_fail, Toast.LENGTH_SHORT).show();
		} else {
			String message = String.format(context.getResources().getString(R.string.backup_success), StorageUtils.BACKUP_DIR + result);
			Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
		}
		pDialog.dismiss();
	}

	@Override
	protected void onPreExecute() {
		// TODO Auto-generated method stub
		pDialog = ProgressDialogManager.showProgressDialog(context, R.string.backing_up);
	}

	@Override
	protected String doInBackground(String... params) {
		// TODO Auto-generated method stub
		String result = Utils.backupApk(context, params[0]);
		return result;
	}

}

